package com.bdqn.shequ.modules.sys.controller;

import com.bdqn.shequ.common.utils.PageUtils;
import com.bdqn.shequ.common.utils.R;
import com.bdqn.shequ.common.validator.ValidatorUtils;
import com.bdqn.shequ.modules.sys.entity.TcMessageEntity;
import com.bdqn.shequ.modules.sys.service.TcMessageService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 消息表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-04-16 09:21:53
 */
@RestController
@RequestMapping("sys/tcmessage")
public class TcMessageController {
    @Autowired
    private TcMessageService tcMessageService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:tcmessage:list")
    public R list(@RequestParam Map<String, Object> params){
        //PageUtils page = tcMessageService.queryPage(params);
        PageUtils page = tcMessageService.selectMessageListPage(Integer.parseInt(params.get("limit").toString()),Integer.parseInt(params.get("page").toString()));
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:tcmessage:info")
    public R info(@PathVariable("id") Long id){
        TcMessageEntity tcMessage = tcMessageService.getById(id);

        return R.ok().put("tcMessage", tcMessage);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:tcmessage:save")
    public R save(@RequestBody TcMessageEntity tcMessage){
        tcMessageService.save(tcMessage);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:tcmessage:update")
    public R update(@RequestBody TcMessageEntity tcMessage){
        ValidatorUtils.validateEntity(tcMessage);
        tcMessageService.updateById(tcMessage);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:tcmessage:delete")
    public R delete(@RequestBody Long[] ids){
        tcMessageService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
